import {listSchoolApi} from "@/api/edutation/school.js";
import {listProfessionalCourseApi, listProfessionalSchoolApi} from "@/api/edutation/professional.js";
import {listCourseApi} from "@/api/edutation/course.js";
import {listCampusApi} from "@/api/edutation/campus.js";
import {listClassApi} from "@/api/edutation/class.js";

export const useCommonData = () => {
  // 获取全部学校列表
  const schoolDataList = ref([])
  const getSchoolDataList = async (query) => {
    try {
      const res = await listSchoolApi(query)
      schoolDataList.value = res.data
    } catch (error) {
      console.log(error)
    }
    return schoolDataList.value
  }

  // 获取校区列表
  const campusDataList = ref([])
  const getCampusDataList = async (query) => {
    try {
      const res = await listCampusApi(query)
      campusDataList.value = res.data
    } catch (error) {
      console.log(error)
    }
    return campusDataList.value
  }


  // 所有专业列表
  const professionalDataList = ref([])
  const getProfessionalDataList = async (query) => {
    try {
      const res = await listProfessionalCourseApi(query)
      professionalDataList.value = res.data
    } catch (error) {
      console.log(error)
    }
    return professionalDataList.value
  }

  // 获取某个学校下开设的专业列表
  const professionalDataListBySchoolId = ref([])
  const getProfessionalDataListBySchoolId = async (schoolId) => {
    try {
      const res = await listProfessionalSchoolApi({schoolId})
      professionalDataListBySchoolId.value = res.data;
    } catch (error) {
      console.log(error)
    }
    return professionalDataListBySchoolId.value
  }

  // 获取班级列表
  const classDataList = ref([])
  const getClassDataList = async (query) => {
    try {
      const res = await listClassApi(query)
      classDataList.value = res.data
    } catch (error) {
      console.log(error)
    }
    return classDataList.value
  }

  // 获取所有课程列表
  const courseDataList = ref([])
  const getCourseDataList = async (query) => {
    try {
      const res = await listCourseApi(query)
      courseDataList.value = res.data
    } catch (error) {
      console.log(error)
    }
    return courseDataList.value
  }







  return {
    schoolDataList,
    getSchoolDataList,
    courseDataList,
    getCourseDataList,
    professionalDataList,
    getProfessionalDataList,
    professionalDataListBySchoolId,
    getProfessionalDataListBySchoolId,
    campusDataList,
    getCampusDataList,
    classDataList,
    getClassDataList
  }
}
